package com.baibei.order.detail;


import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.baibei.model.Area;
import com.baibei.model.BuyDirection;
import com.baibei.model.OrderInfo;
import com.baibei.model.QuotationInfo;
import com.baibei.module.AreaHelper;
import com.baibei.module.GlideApp;
import com.baibei.order.R;
import com.baibei.order.R2;
import com.baibei.widget.PriceTextView;
import com.blankj.utilcode.utils.TimeUtils;
import com.rae.swift.Rx;

import butterknife.BindView;

/**
 * 收支记录详情
 */
public class RecordFragment extends OrderDetailFragment {
    private static final String ARG_PARAM1 = "param1";
    @BindView(R2.id.tv_order_amount)
    TextView mTvOrderAmount;
    @BindView(R2.id.tv_order_unsubscribe_amount)
    TextView mTvOrderUnsubscribeAmount;
    @BindView(R2.id.tv_order_num)
    TextView mTvOrderNum;
    @BindView(R2.id.tv_order_date)
    TextView mTvOrderDate;
    @BindView(R2.id.tv_order_unsubscribe_date)
    TextView mTvOrderUnsubscribeDate;
    @BindView(R2.id.tv_order_fee)
    TextView mTvOrderFee;
    @BindView(R2.id.tv_order_service)
    TextView mTvOrderService;
    @BindView(R2.id.tv_order_income)
    PriceTextView mTvOrderIncome;
    @BindView(R2.id.iv_product)
    ImageView mIvProduct;
    @BindView(R2.id.iv_flag)
    ImageView mIvFlag;
    @BindView(R2.id.tv_product_name)
    TextView mTvProductName;
    @BindView(R2.id.tv_type)
    TextView mTvType;
    @BindView(R2.id.tv_count)
    TextView mTvCount;
    @BindView(R2.id.tv_income_total)
    PriceTextView mTvIncomeTotal;
    @BindView(R2.id.tv_rise)
    TextView mTvRise;
    @BindView(R2.id.tv_decline)
    TextView mTvDecline;

    private OrderInfo mInfo;

    public RecordFragment() {
    }

    public static RecordFragment newInstance(OrderInfo info) {
        RecordFragment fragment = new RecordFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM1, info);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mInfo = (OrderInfo) getArguments().getSerializable(ARG_PARAM1);

        }
    }


    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.fragment_record;
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        if (isAdded() && mInfo != null) {
            mIvFlag.setImageResource(AreaHelper.getImageResource(Area.valueOf(mInfo.getArea())));

            //logo
            GlideApp.with(this).load(mInfo.getProductpic()).placeholder(R.color.dividerColor).into(mIvProduct);
            //商品名称
            mTvProductName.setText(mInfo.getName());
            mTvType.setText(mInfo.getBuydirection() == BuyDirection.DIRECTION_CURRENT_PRICE ? R.string.current_price_order : R.string.settle_price_order);
            //差价合计
            mTvCount.setText(String.format(getString(R.string.order_dtail_figure_count), mInfo.getCount()));
            mTvIncomeTotal.setPrice(mInfo.getPlamount());
            mTvOrderAmount.setText(Rx.formatPrice(mInfo.getBuyprice()));
            mTvOrderUnsubscribeAmount.setText(Rx.formatPrice(mInfo.getSellprice()));
            mTvOrderNum.setText(mInfo.getOrdernum());
            mTvOrderDate.setText(TimeUtils.millis2String(mInfo.getAddtime()));
            mTvOrderUnsubscribeDate.setText(TimeUtils.millis2String(mInfo.getSelltime()));
            mTvOrderFee.setText(Rx.formatPrice(mInfo.getBuyMoney()));
            mTvOrderService.setText(Rx.formatPrice(mInfo.getFee()));
            mTvOrderIncome.setPrice(mInfo.getActualAmount());

            mTvRise.setText(mInfo.getToplimit() == 0 ? "无" : String.format("%s%%", mInfo.getToplimit() * 100));
            mTvDecline.setText(mInfo.getBottomlimit() == 0 ? "无" : String.format("%s%%", mInfo.getBottomlimit() * 100));
        }
    }

    @Override
    public void refresh(SparseArray<QuotationInfo> quotations) {

    }

}
